Start a Mosquitto container first. For example:
codes\_demo\1_start_broker.sh
to start a Mosquitto container on Raspberry Pi.mqtt_config\mqtt
.allow_anonymous true
in mqtt_config\mqtt\config\mosquitto.conf
to allow anonymous client.
In [ ]:
import os
import sys
import time
sys.path.append(os.path.abspath(os.path.join(os.path.pardir, '..\\codes', 'client')))
sys.path.append(os.path.abspath(os.path.join(os.path.pardir, '..\\codes', 'node')))
sys.path.append(os.path.abspath(os.path.join(os.path.pardir, '..\\codes', 'shared')))
sys.path.append(os.path.abspath(os.path.join(os.path.pardir, '..\\codes', 'micropython')))
import client
from collections import OrderedDict
In [ ]:
the_client = client.Client()
the_client.start()
while not the_client.status['Is connected']:
time.sleep(1)
print('Node not ready yet.')
In [ ]:
# messages _____________________________________________
messages = OrderedDict()
messages['show text'] = {'message_type': 'command',
'command': 'show text',
'kwargs': {'text': 'Hello World!',
'x': 0, 'y': 0,
'clear_first': True,
'show_now': True,
'hold_seconds': 5}}
In [ ]:
print('\n[______________ Sending messages ______________]\n')
remote_node = 'NodeMCU_8a00'
# send out the messages
for message in messages.values():
time.sleep(0.1) # PyCharm needs this delay.
the_client.request(remote_node, message)
In [ ]:
# Stopping
the_client.stop()
the_client = None
print('\n[________________ Demo stopped ________________]\n')
In [ ]: